package top.atcra.rpc.transport.utils;

import cn.hutool.core.lang.Pair;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import top.atcra.rpc.transport.config.ClientRPCChannelInitializer;

/**
 * 根据传输层类型，创建对应的Netty Bootstrap
 *
 * @author atcra
 * @date 2025-3-25
 */
public class NettyBootstrapFactory {
    private NettyBootstrapFactory() {
    }

    public static Pair<Bootstrap, NioEventLoopGroup> getClientBootstrap() {
        Bootstrap bootstrap = new Bootstrap();
        NioEventLoopGroup group = new NioEventLoopGroup(2);
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ClientRPCChannelInitializer());
//            .option(ChannelOption.SO_REUSEADDR, true);
        return Pair.of(bootstrap, group);
        //.localAddress(IPAddrUtil.getAvailablePort());
    }
}
